// 查询数据库中是否存在OrderId
const cloud = require('wx-server-sdk');
cloud.init({
  env:cloud.DYNAMIC_CURRENT_ENV
});
const db = cloud.database();
exports.main = async (event, context) =>{
  const res =  await db.collection("userOrders").where({
    orderId:event.orderId
  }).get();
  if(!res.data.length){
    return {
      code:200
    }
  }
  if(res.data.length > 1){
    return {
      code:500,
      msg:"下单失败，存在多条订单编号，请联系管理员解决"
    }
  }
  return {
    code:500,
    msg:"下单失败，已存在该订单编号("+event.orderId+")，请填写另外的另外订单编号"
  }
}